package com.emm.yixun.website.controller.customer;
//框架包
import java.util.*;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
//common
import com.emm.yixun.common.page.PageUtil;
import com.emm.yixun.common.page.Page;
import com.emm.yixun.common.response.Response;
import com.emm.yixun.common.response.ResponseList;
import com.emm.yixun.common.model.User;
//website
import com.emm.yixun.website.common.ajax.AjaxRes;
import com.emm.yixun.website.common.utils.base.Const;
import com.emm.yixun.website.common.utils.security.ShiroUtil;
import com.emm.yixun.website.controller.base.BaseController;

import com.emm.yixun.common.model.Customer;
import com.emm.yixun.common.model.CustomerAnswer;
import com.emm.yixun.common.model.CustomerAnswerInfo;
import com.emm.yixun.common.model.CustomerProjectQuestion;
import com.emm.yixun.common.model.Project;
//变化的引用
import com.emm.yixun.common.model.ProjectQuestion;
import com.emm.yixun.common.model.ProjectQuestionInfo;
import com.emm.yixun.common.model.ProjectQuestionnaire;
import com.emm.yixun.common.model.Tag;
import com.emm.yixun.common.model.TagInfo;
import com.emm.yixun.common.model.dto.CustomerDto;
import com.emm.yixun.common.model.dto.CustomerProjectQuestionDto;
import com.emm.yixun.common.model.dto.ProjectQuestionDto;
import com.emm.yixun.common.model.dto.TagDto;
import com.emm.yixun.common.model.dto.UserDto;
import com.emm.yixun.common.model.enums.DelFlagEnum;
import com.emm.yixun.common.model.enums.IsAvlidEnum;
import com.emm.yixun.common.model.enums.UserStatusEnum;
import com.emm.yixun.customer.service.CustomerAnswerServiceFacade;
import com.emm.yixun.customer.service.CustomerProjectQuestionServiceFacade;
import com.emm.yixun.customer.service.CustomerServiceFacade;
import com.emm.yixun.customer.service.ProjectQuestionServiceFacade;
import com.emm.yixun.customer.service.ProjectQuestionnaireServiceFacade;
import com.emm.yixun.customer.service.TagServiceFacade;
import com.emm.yixun.estate.service.ProjectServiceFacade;
import com.emm.yixun.system.service.UserServiceFacade;

@Controller
@RequestMapping("/customer/projectQuestion/")
public class ProjectQuestionController extends BaseController<ProjectQuestion>{
	
	@Autowired
	private ProjectQuestionnaireServiceFacade projectQuestionnaireServiceFacade;
	
	@Autowired
	private ProjectQuestionServiceFacade projectQuestionServiceFacade;
	
	@Autowired
    private TagServiceFacade tagServiceFacade;
	
	@Autowired
	private ProjectServiceFacade projectServiceFacade;
	
	@Autowired
	private UserServiceFacade userServiceFacade;
	
	@Autowired
	private CustomerServiceFacade customerServiceFacade;
	
	@Autowired
	private CustomerAnswerServiceFacade customerAnswerServiceFacade;
	
	@Autowired
	private CustomerProjectQuestionServiceFacade customerProjectQuestionServiceFacade;
	
	@RequestMapping(value="index")
	public String index(ModelMap map){
		if(doSecurityIntercept(Const.RESOURCES_TYPE_MENU)){
			//查询菜单按钮权限
			map.put("permitBtn", getPermitBtn(Const.RESOURCES_TYPE_FUNCTION));		
			return "/customer/projectQuestion/list";
		}
		return Const.NO_AUTHORIZED_URL;
	}
	
	//新增返回实体对象
	@RequestMapping(value="add", method=RequestMethod.POST)
	@ResponseBody
    public AjaxRes  add(ProjectQuestionDto dto){
    	AjaxRes ar=getAjaxRes();
    	
    	/*
    	 *1.判断权限 
    	 *2.调用新增接口
    	 *3.返回信息
    	*/
        if(ar.setNoAuth(doSecurityIntercept(Const.RESOURCES_TYPE_BUTTON,"customer:projectQuestion:add"))){
        	try {
        		User user=ShiroUtil.getCurrentUser();
        		dto.setMerchantId(user.getMerchantId());
        		dto.setCreateUser(user.getId());
        		dto.setDelFlag("0");
        		dto.setUpdateUser(user.getId());
        		dto.setUpdateTime(new Date());
				Response<ProjectQuestionDto> response=projectQuestionServiceFacade.save(dto);
				if(response.isSuccess()){
					ar.setSucceedMsg(Const.SAVE_SUCCEED);
				}else{
					ar.setFailMsg(Const.SAVE_FAIL);
				}
			} catch (Exception e) {
				logger.error(e.toString(),e);
				ar.setFailMsg(Const.SAVE_FAIL);
			}
    	}
    	return ar;
    }
	//查看
	@RequestMapping(value="view", method=RequestMethod.POST)
	@ResponseBody
    public AjaxRes  view(Long id){
    	AjaxRes ar=getAjaxRes();
    	/*
    	 *1.判断权限 
    	 *2.调用查看接口
    	 *3.返回信息
    	*/
        if(ar.setNoAuth(doSecurityIntercept(Const.RESOURCES_TYPE_BUTTON,"customer:projectQuestion:view"))){
        	try {
				Response<ProjectQuestion> response=projectQuestionServiceFacade.findById(id);
				if(response.isSuccess()){
					ar.setSucceed(response.getEntity());
				}else {
					ar.setFailMsg(Const.DATA_FAIL);
				}
			} catch (Exception e) {
				logger.error(e.toString(),e);
				ar.setFailMsg(Const.DATA_FAIL);
			}
    	}
    	return ar;
    }
	
	//修改
	@RequestMapping(value="edit", method=RequestMethod.POST)
	@ResponseBody
    public AjaxRes  edit(ProjectQuestionDto dto){
    	AjaxRes ar=getAjaxRes();
    	/*
    	 *1.判断权限 
    	 *2.调用修改接口
    	 *3.返回信息
    	*/
        if(ar.setNoAuth(doSecurityIntercept(Const.RESOURCES_TYPE_BUTTON,"customer:projectQuestion:edit"))){
        	try {
        		Response<Integer> response=projectQuestionServiceFacade.updateByPrimaryKey(dto, true);
				if(response.isSuccess()){
					ar.setSucceedMsg(Const.UPDATE_SUCCEED);
				}else{
					ar.setFailMsg(Const.UPDATE_FAIL);
				}
			} catch (Exception e) {
				logger.error(e.toString(),e);
				ar.setFailMsg(Const.UPDATE_FAIL);
			}
    	}
    	return ar;
    }
	
	//删除
	@RequestMapping(value="delete", method=RequestMethod.POST)
	@ResponseBody
    public AjaxRes  delete(Long id){
    	AjaxRes ar=getAjaxRes();
    	/*
    	 *1.判断权限 
    	 *2.调用查看接口
    	 *3.返回信息
    	*/
        if(ar.setNoAuth(doSecurityIntercept(Const.RESOURCES_TYPE_BUTTON,"customer:projectQuestion:delete"))){
        	try {
        		Response<Integer> response=projectQuestionServiceFacade.deleteByPrimaryKey(id);
				if(response.isSuccess()){
					ar.setSucceedMsg(Const.DEL_SUCCEED);
				}else {
					ar.setFailMsg(Const.DEL_FAIL);
				}
			} catch (Exception e) {
				logger.error(e.toString(),e);
				ar.setFailMsg(Const.DEL_FAIL);
			}
    	}
    	return ar;
    }
	
	//分页查询
	@RequestMapping(value="list", method=RequestMethod.POST)
	@ResponseBody
    public AjaxRes  list(ProjectQuestionDto dto,Integer pageSize,Integer pageNum){
    	AjaxRes ar=getAjaxRes();
    	/*
    	 *1.判断权限 
    	 *2.调用分页查询接口
    	 *3.返回信息
    	*/
        if(ar.setNoAuth(doSecurityIntercept(Const.RESOURCES_TYPE_BUTTON,"customer:projectQuestion:list"))){
        	try {
        		Page<ProjectQuestion> response=projectQuestionServiceFacade.findPageByDto(dto, PageUtil.begin(pageNum, pageSize),pageSize);
                if(response.getSuccess()){
                    if(null==response.getRows()) {
                        response.setRows(new ArrayList<ProjectQuestion>());
                    }
                	response.setPageNumber(pageNum);
                	ar.setSucceed(response);
                }else{
                	ar.setFailMsg(Const.DATA_FAIL);
                }
			} catch (Exception e) {
				logger.error(e.toString(),e);
				ar.setFailMsg(Const.DATA_FAIL);
			}
    	}
    	return ar;
    }
	
	//问卷修改-查询
	@RequestMapping(value="questionList", method=RequestMethod.POST)
	@ResponseBody
    public AjaxRes questionList(HttpServletRequest request){
    	AjaxRes ar=getAjaxRes();
    	/*
    	 *1.判断权限 
    	 *2.调用分页查询接口
    	 *3.返回信息
    	*/
        //if(ar.setNoAuth(doSecurityIntercept(Const.RESOURCES_TYPE_BUTTON,"customer:projectQuestion:list"))){
        	try {
        		String projectQuestionnaireId = request.getParameter("questionnaireId");
        		String level = request.getParameter("level");
        		String problemCode = request.getParameter("problemCode");
        		
        		ProjectQuestionDto dto = new ProjectQuestionDto();
        		dto.setProjectQuestionnaireId(Long.parseLong(projectQuestionnaireId));
        		//问题等级
        		if(StringUtils.isNotBlank(level)){
        			dto.setLevel(Long.parseLong(level));
        		}
        		//问题编号
        		if(StringUtils.isNotBlank(problemCode)){
        			dto.setProblemCode(problemCode);
        		}
        		dto.setIsValid(IsAvlidEnum.AVILD.getNo());
    			dto.setDelFlag(DelFlagEnum.UNDEL.getNo());
    			dto.addAsc("sort");
        		ResponseList<ProjectQuestionInfo> response = projectQuestionServiceFacade.questionList(dto);
        		if(response.isSuccess()){
                    if(null==response.getEntity()) {
                        response.setEntity(new ArrayList<ProjectQuestionInfo>());
                    }
                	ar.setSucceed(response);
                }else{
                	ar.setFailMsg(Const.DATA_FAIL);
                }
        		
			} catch (Exception e) {
				logger.error(e.toString(),e);
				ar.setFailMsg(Const.DATA_FAIL);
			}
    	//}
    	return ar;
    }
	
	//新增返回实体对象
	@RequestMapping(value="addOrUpdate", method=RequestMethod.POST)
	@ResponseBody
    public AjaxRes addOrUpdate(HttpServletRequest request){
    	AjaxRes ar=getAjaxRes();
    	
    	/*
    	 *1.判断权限 
    	 *2.调用新增接口
    	 *3.返回信息
    	*/
        //if(ar.setNoAuth(doSecurityIntercept(Const.RESOURCES_TYPE_BUTTON,"customer:questionnaireQuestion:add"))){
        	try {
        		//模板主表ID
        		String projectQuestionnaireId = request.getParameter("projectQuestionnaireId");
        		if(StringUtils.isBlank(projectQuestionnaireId)){
        			ar.setFailMsg(Const.SAVE_FAIL);
        			return ar;
        		}
        		//获取问卷内容
        		String arrayJson = request.getParameter("json");
        		if(StringUtils.isBlank(arrayJson)){
        			ar.setFailMsg(Const.SAVE_FAIL);
        			return ar;
        		}
        		//问卷问题表ID（不为空时表示修改问卷）
        		String questionId = request.getParameter("questionId");
        		User user=ShiroUtil.getCurrentUser();
        		ProjectQuestionInfo dto = new ProjectQuestionInfo();
        		dto.setProjectQuestionnaireId(Long.parseLong(projectQuestionnaireId));
        		dto.setArrayJson(arrayJson); 
        		dto.setMerchantId(user.getMerchantId());
    			dto.setCreateUser(user.getId());
    			dto.setCreateTime(new Date());
    			//判断是否为修改，questionId为空为新增
    			if(StringUtils.isNotBlank(questionId)){
    				dto.setId(Long.parseLong(questionId));
    			}
				Response<String> response = projectQuestionServiceFacade
						.saveQuestionnaire(dto);
				if(response.isSuccess()){
					ar.setSucceedMsg(Const.SAVE_SUCCEED);
				}else{
					ar.setFailMsg(Const.SAVE_FAIL);
				}
			} catch (Exception e) {
				logger.error(e.toString(),e);
				ar.setFailMsg(Const.SAVE_FAIL);
			}
    	//}
    	return ar;
    }
	
	//问卷修改-查询
	@RequestMapping(value="questionAyalyzeList", method=RequestMethod.POST)
	@ResponseBody
    public AjaxRes questionAyalyzeList(HttpServletRequest request){
    	AjaxRes ar=getAjaxRes();
    	/*
    	 *1.判断权限 
    	 *2.调用分页查询接口
    	 *3.返回信息
    	*/
    	try {
    		String projectQuestionnaireId = request.getParameter("questionnaireId");
    		String level = request.getParameter("level");
    		String problemCode = request.getParameter("problemCode");
    		
    		ProjectQuestionDto dto = new ProjectQuestionDto();
    		dto.setProjectQuestionnaireId(Long.parseLong(projectQuestionnaireId));
    		//问题等级
    		if(StringUtils.isNotBlank(level)){
    			dto.setLevel(Long.parseLong(level));
    		}
    		//问题编号
    		if(StringUtils.isNotBlank(problemCode)){
    			dto.setProblemCode(problemCode);
    		}
    		dto.setIsValid(IsAvlidEnum.AVILD.getNo());
			dto.setDelFlag(DelFlagEnum.UNDEL.getNo());
			dto.addAsc("sort");
    		ResponseList<ProjectQuestionInfo> response = projectQuestionServiceFacade.questionAyalyzeList(dto);
    		if(response.isSuccess()){
                if(null==response.getEntity()) {
                    response.setEntity(new ArrayList<ProjectQuestionInfo>());
                }
            	ar.setSucceed(response);
            }else{
            	ar.setFailMsg(Const.DATA_FAIL);
            }
    		
		} catch (Exception e) {
			logger.error(e.toString(),e);
			ar.setFailMsg(Const.DATA_FAIL);
		}
    	return ar;
    }
	
	/**
	 * 打开标签库
	 * @param map
	 * @return
	 */
	@RequestMapping(value="openCusTag")
    public String openCusTag(Long customerId, ModelMap map){
	    TagDto dto = new TagDto();
	    dto.setParentId(0L);
	    dto.setDelFlag(DelFlagEnum.UNDEL.getNo());
	    ResponseList<Tag> res = tagServiceFacade.findByDto(dto);
	    if(res.isSuccess()){
	        map.addAttribute("tagList", res.getEntity());
	    }
	    //从客户标签页打开时会传入customerId
	    map.addAttribute("customerId", customerId);
        return "/system/questionnaire/tag/survey";
    }
	
	/**
	 * 查询客户问卷标签库
	 * @param request
	 * @param typeId 标签分组ID
	 * @param tagName 问题内容
	 * @param notIncluded 不包含在内的问题
	 * @return
	 */
    @RequestMapping(value="queryCusTag", method=RequestMethod.POST)
    @ResponseBody
    public AjaxRes queryCusTag(HttpServletRequest request, Long typeId, String tagName, String notIncluded,
            Long projectQuestionId, Long customerId, Integer pageSize,Integer pageNum){
        AjaxRes ar=getAjaxRes();
        try {
            //将需要过滤的问题ID去掉中括号
            if(projectQuestionId != null){
                //当参数为[select]从项目问卷表获取已生成的问题ID，并拼接过滤条件
                ProjectQuestionDto qDto = new ProjectQuestionDto();
                qDto.setProjectQuestionnaireId(projectQuestionId);
                qDto.setIsValid(IsAvlidEnum.AVILD.getNo());
                qDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
                Response<String> res = projectQuestionServiceFacade.getCusTagList(qDto, customerId);
                if(res.isSuccess()){
                    notIncluded = res.getEntity();
                }
            }else if(StringUtils.isNotBlank(notIncluded) 
                    && !"[]".equals(notIncluded)){
                //当参数不为空，并且为空数组时，拼接过滤条件
                notIncluded = notIncluded.replace("["," ext.id not in (").replace("]",")");
            }else{
                notIncluded = null;
            }
            TagDto dto = new TagDto();
            dto.setTagName(tagName);
            dto.setParentId(typeId);
            dto.setSql(notIncluded);
            dto.setDelFlag(DelFlagEnum.UNDEL.getNo());
            dto.addAsc("ext.id");
            Page<TagInfo> response = tagServiceFacade.getTagPage(dto, PageUtil.begin(pageNum, pageSize), pageSize);
            if(response.getSuccess()){
                if(null==response.getRows()) {
                    response.setRows(new ArrayList<TagInfo>());
                }
                response.setPageNumber(pageNum);
                ar.setSucceed(response);
            }else{
                ar.setFailMsg(Const.DATA_FAIL);
            }
            
        } catch (Exception e) {
            logger.error(e.toString(),e);
            ar.setFailMsg(Const.DATA_FAIL);
        }
        return ar;
    }
    
    /**
     * 查询客户标签列表
     * @param request
     * @param ids 
     * @return
     */
    @RequestMapping(value="queryTagQuestionList", method=RequestMethod.POST)
    @ResponseBody
    public AjaxRes queryTagQuestionList(HttpServletRequest request, String ids){
        AjaxRes ar=getAjaxRes();
        try {
            //查询对应ID的 标签问题
            if(StringUtils.isNotBlank(ids)){
                ids = ids.replace("["," ext.id in (").replace("]",")");
            }
            TagDto dto = new TagDto();
            dto.setSql(ids);
            dto.setDelFlag(DelFlagEnum.UNDEL.getNo());
            dto.addAsc("ext.id");
            ResponseList<TagInfo> response = tagServiceFacade.getTagQuestionList(dto);
            if(response.isSuccess()){
                if(null==response.getEntity()){
                    response.setEntity(new ArrayList<TagInfo>());
                }
                ar.setSucceed(response);
            }else{
                ar.setFailMsg(Const.DATA_FAIL);
            }
            
        } catch (Exception e) {
            logger.error(e.toString(),e);
            ar.setFailMsg(Const.DATA_FAIL);
        }
        return ar;
    }
    
    //查询问卷标题及项目名称
  	@RequestMapping(value="questionnaireTitle", method=RequestMethod.POST)
  	@ResponseBody
    public AjaxRes questionnaireTitle(HttpServletRequest request){
      	AjaxRes ar = getAjaxRes();
      	try {
			String projectQuestionnaireId = request.getParameter("questionnaireId");
			if (StringUtils.isBlank(projectQuestionnaireId)) {
				ar.setFailMsg("未获取到问卷");
				ar.setRes(0);
				return ar;
			} 
			Map<Object, Object> resMap = new HashMap<Object, Object>();
			//查询问卷
			Response<ProjectQuestionnaire> resNaire = projectQuestionnaireServiceFacade
					.findById(Long.parseLong(projectQuestionnaireId));
			if(!resNaire.isSuccess() || resNaire.getEntity() == null) {
				ar.setFailMsg("未获取到问卷");
				ar.setRes(0);
				return ar;
			}
			ProjectQuestionnaire naire = resNaire.getEntity();
			resMap.put("title", naire.getName());
			//查询项目
			Response<Project> resProject = projectServiceFacade
					.findById(naire.getProjectId());
			if(!resProject.isSuccess() || resProject.getEntity() == null) {
				ar.setFailMsg("未获取到项目名称");
				ar.setRes(0);
				return ar;
			}
			Project project = resProject.getEntity();
			resMap.put("projectId", project.getId());
			resMap.put("projectName", project.getProjectName());
			//查询商户下的经纪人
			UserDto dto = new UserDto();
			dto.setMerchantId(project.getMerchantId());
			dto.setUserStatus(UserStatusEnum.IN_USE.getNo());
			dto.setDelFlag(DelFlagEnum.UNDEL.getNo());
			ResponseList<User> resUser = userServiceFacade.findByDto(dto);
			if(!resUser.isSuccess() || resUser.getEntity() == null) {
				ar.setFailMsg("未获取到经纪人");
				ar.setRes(0);
				return ar;
			}
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(16);
			for(User user: resUser.getEntity()) {
				if("1".equals(user.getIsAdmin())) {
					continue;
				}
				Map<String, Object> userMap = new HashMap<String, Object>(2);
				userMap.put("userId", user.getId());
				userMap.put("userName", user.getUserName());
				list.add(userMap);
			}
			resMap.put("userList", list);
			ar.setObj(resMap);
			ar.setRes(1);
		} catch (Exception e) {
			logger.error("查询问卷标题及项目名称失败", e);
			ar.setFailMsg("未获取到问卷");
			ar.setRes(0);
		}
		return ar;
  	}
  	
  	/**
  	 * H5保存问卷答案接口
  	 * @param request
  	 * @return
  	 */
  	@RequestMapping(value="addAnswerByH5", method=RequestMethod.POST)
  	@ResponseBody
    public AjaxRes addAnswerByH5(Long projectQuestionnaireId, String arrayJson, 
    		String customerName, String customerPhone, Long projectId){
      	AjaxRes ar=getAjaxRes();
      	try {
      		//校验字段
      		if(projectQuestionnaireId == null || StringUtils.isBlank(arrayJson)
      			|| StringUtils.isBlank(customerName) || StringUtils.isBlank(customerPhone)
      			|| projectId == null){
      			ar.setFailMsg(Const.SAVE_FAIL);
      			return ar;
      		}
      		//客户ID和经纪人ID为-1，表示未匹配到客户
      		long customerId = -1L;
      		long agentId = -1L;
      		//根据项目ID、客户姓名和客户手机号查询匹配的客户ID
      		CustomerDto entity = new CustomerDto();
      		entity.setCustomerName(customerName);
      		entity.setCustomerPhone(customerPhone);
      		entity.setProjectId(projectId);
      		entity.setDelFlag(DelFlagEnum.UNDEL.getNo());
      		ResponseList<Customer> resList = customerServiceFacade.findByDto(entity);
      		if(resList.isSuccess() && resList.getEntity() != null) {
      			Customer cus = resList.getEntity().get(0);
      			customerId = cus.getId();
      			//查询经纪人ID
      			UserDto dto = new UserDto();
      			dto.setUserCode(cus.getUserCode());
      			ResponseList<User> listUser = userServiceFacade.findByDto(dto);
      			if(listUser.isSuccess() && listUser.getEntity() != null) {
      				agentId = listUser.getEntity().get(0).getId();
      			}
      		}
      		//查询该客户是否已有其他问卷
      		CustomerProjectQuestionDto cqDto = new CustomerProjectQuestionDto();
      		if(customerId != -1L) {
      			cqDto.setCustomerId(customerId);
      		}else{
          		cqDto.setCustomerPhone(customerPhone);
      		}
      		cqDto.setProjectId(projectId);
      		ResponseList<CustomerProjectQuestion> listQuestion = customerProjectQuestionServiceFacade
      				.findByDto(cqDto);
      		if(!listQuestion.isSuccess()) {
      			ar.setFailMsg(Const.SAVE_FAIL);
      			return ar;
      		}
      		if(listQuestion.getEntity() != null && listQuestion.getEntity().size() > 0 ) {
      			ar.setFailMsg("您已填写过问卷，不能重复填写");
      			return ar;
      		}
      		
      		//保存问卷
      		CustomerAnswerInfo dto = new CustomerAnswerInfo();      		
      		dto.setCustomerId(customerId);
      		dto.setCustomerName(customerName);
      		dto.setCustomerPhone(customerPhone);
      		dto.setArrayJson(arrayJson);
      		//创建人等于经纪人
  			dto.setCreateUser(agentId); 
  			dto.setCreateTime(new Date());
		    dto.setProjectQuestionnaireId(projectQuestionnaireId);
		    Response<CustomerAnswer> response = customerAnswerServiceFacade.add(dto);
  			if(response.isSuccess()){
  				ar.setSucceed(response.getEntity());
			}else{
				ar.setFailMsg(Const.SAVE_FAIL);
			}
		} catch (Exception e) {
			logger.error(e.toString(),e);
			ar.setFailMsg(Const.SAVE_FAIL);
		}
      	return ar;
    }
    
  	/**
  	 * 匹配客户
  	 * @param request
  	 * @return
  	 */
  	@RequestMapping(value="matchCustomer", method=RequestMethod.POST)
  	@ResponseBody
    public AjaxRes matchCustomer(Long projectQuestionnaireId, String customerName, String customerPhone,
    		String oldName, String oldPhone){
      	AjaxRes ar=getAjaxRes();
      	try {
      		//校验字段
      		if(projectQuestionnaireId == null || StringUtils.isBlank(customerName) 
      				|| StringUtils.isBlank(customerPhone)){
      			ar.setFailMsg(Const.SAVE_FAIL);
      			return ar;
      		}
      		Response<CustomerAnswer> response = customerAnswerServiceFacade
      				.matchCustomer(projectQuestionnaireId, customerName, customerPhone, 
      						oldName, oldPhone);
  			if(response.isSuccess()){
  				ar.setSucceedMsg("匹配成功");
			}else{
				ar.setFailMsg(response.getResultMessage());
			}
      	} catch (Exception e) {
			logger.error(e.toString(),e);
			ar.setFailMsg("匹配成功");
		}
      	return ar;
    }
}
